package cn.tedu.javagame.Plane;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;


public class EnemyBullet {
    int x,y;
    static Image bulletImg;
    static Image enemyBulletImg; // 存储上下翻转后的子弹图像

    static {
        // 加载原始子弹图像
        bulletImg = new ImageIcon("plane/bullets.png").getImage();

        // 将原始图像转换为BufferedImage以便处理
        BufferedImage bufferedBulletImg = toBufferedImage(bulletImg);

        // 创建垂直翻转的变换
        AffineTransform transform = AffineTransform.getScaleInstance(1, -1);
        transform.translate(0, -bufferedBulletImg.getHeight());

        // 应用变换并创建新图像
        AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        BufferedImage flippedImage = op.filter(bufferedBulletImg, null);

        // 将处理后的图像赋值给新的静态变量
        enemyBulletImg = flippedImage;
    }

    // 辅助方法：将Image转换为BufferedImage
    private static BufferedImage toBufferedImage(Image image) {
        if (image instanceof BufferedImage) {
            return (BufferedImage) image;
        }

        // 创建具有透明背景的BufferedImage
        BufferedImage bufferedImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB
        );

        // 将图像绘制到BufferedImage中
        Graphics2D g2d = bufferedImage.createGraphics();
        g2d.drawImage(image, 0, 0, null);
        g2d.dispose();

        return bufferedImage;
    }

    public EnemyBullet(int x, int y){
        this.x=x;
        this.y=y;

    }
    public void move(){
        this.y+=5;
    }

    public void hitEnemy(){}
}